\hypertarget{encoding_8c}{}\doxysubsection{extern/libembroidery/src/encoding.c File Reference}
\label{encoding_8c}\index{extern/libembroidery/src/encoding.c@{extern/libembroidery/src/encoding.c}}
{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$math.\+h$>$}\newline
{\ttfamily \#include \char`\"{}embroidery\+\_\+internal.\+h\char`\"{}}\newline
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \mbox{\hyperlink{encoding_8c_a05863b88d4cb505762fa5c5ec4191224}{write\+\_\+24bit}} (FILE $\ast$file, int)
\begin{DoxyCompactList}\small\item\em {\itshape file} {\itshape x} \end{DoxyCompactList}\item 
\mbox{\hyperlink{embroidery_8h_acde9d757854564332fd795a084ec88b3}{Emb\+Color}} \mbox{\hyperlink{encoding_8c_a49c180e69d4ac6d46e68b64adb74d7ae}{emb\+Color\+\_\+from\+Hex\+Str}} (char $\ast$val)
\begin{DoxyCompactList}\small\item\em Converts a 6 digit hex string (I.\+E. \char`\"{}00\+FF00\char`\"{}) into an Emb\+Color and returns it. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{encoding_8c_ad8b4161c499a38795d7a740300d9e5bd}{reverse\+\_\+byte\+\_\+order}} (void $\ast$b, int bytes)
\item 
int \mbox{\hyperlink{encoding_8c_a9a4ef6979894437de607ac59967d6691}{decode\+\_\+t01\+\_\+record}} (unsigned char b\mbox{[}3\mbox{]}, int $\ast$x, int $\ast$y, int $\ast$flags)
\item 
void \mbox{\hyperlink{encoding_8c_a185446b8993b1f6a16bca08cc0032cba}{encode\+\_\+t01\+\_\+record}} (unsigned char b\mbox{[}3\mbox{]}, int x, int y, int flags)
\item 
int \mbox{\hyperlink{encoding_8c_a6f2eb7f943597426ecce56ce45c92896}{encode\+\_\+tajima\+\_\+ternary}} (unsigned char b\mbox{[}3\mbox{]}, int x, int y)
\item 
void \mbox{\hyperlink{encoding_8c_aeead1c7cae8d2d87aa74a32f0eeae808}{decode\+\_\+tajima\+\_\+ternary}} (unsigned char b\mbox{[}3\mbox{]}, int $\ast$x, int $\ast$y)
\item 
void \mbox{\hyperlink{encoding_8c_a2b001600fdee799e57a8ea00e9b73583}{pfaff\+Encode}} (FILE $\ast$file, int dx, int dy, int flags)
\item 
\mbox{\hyperlink{embroidery_8h_a2082be9aabfb541dff1825c4ca6a05cd}{Emb\+Real}} \mbox{\hyperlink{encoding_8c_a43cfefba2fb750ffa5eca5b7749b53f9}{pfaff\+Decode}} (unsigned char a1, unsigned char a2, unsigned char a3)
\item 
unsigned char \mbox{\hyperlink{encoding_8c_a558c902db31be6221139e394313e4a0c}{mit\+Encode\+Stitch}} (\mbox{\hyperlink{embroidery_8h_a2082be9aabfb541dff1825c4ca6a05cd}{Emb\+Real}} value)
\begin{DoxyCompactList}\small\item\em {\itshape value} \end{DoxyCompactList}\item 
int \mbox{\hyperlink{encoding_8c_a896703c85b788f1c46053d826cdd3524}{mit\+Decode\+Stitch}} (unsigned char value)
\begin{DoxyCompactList}\small\item\em {\itshape value} \end{DoxyCompactList}\item 
int \mbox{\hyperlink{encoding_8c_a1fe39861516c14e3142add13ce9929b1}{decode\+New\+Stitch}} (unsigned char value)
\begin{DoxyCompactList}\small\item\em {\itshape value} \end{DoxyCompactList}\item 
void \mbox{\hyperlink{encoding_8c_ac14e60a4d0a0fae16f22ccbbb2373e2a}{emb\+Int\+\_\+read}} (FILE $\ast$f, char $\ast$label, void $\ast$b, int mode)
\item 
void \mbox{\hyperlink{encoding_8c_a6afc577513abd5034e24efdcbdd7f9f5}{emb\+Int\+\_\+write}} (FILE $\ast$f, char $\ast$label, void $\ast$b, int mode)
\end{DoxyCompactItemize}


\doxysubsubsection{Detailed Description}
The functions in this file are grouped together to aid the developer\textquotesingle{}s understanding of the similarities between the file formats. This also helps reduce errors between reimplementation of the same idea.

For example\+: the Tajima ternary encoding of positions is used by at least 4 formats and the only part that changes is the flag encoding. 

\doxysubsubsection{Function Documentation}
\mbox{\Hypertarget{encoding_8c_a9a4ef6979894437de607ac59967d6691}\label{encoding_8c_a9a4ef6979894437de607ac59967d6691}} 
\index{encoding.c@{encoding.c}!decode\_t01\_record@{decode\_t01\_record}}
\index{decode\_t01\_record@{decode\_t01\_record}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{decode\_t01\_record()}{decode\_t01\_record()}}
{\footnotesize\ttfamily int decode\+\_\+t01\+\_\+record (\begin{DoxyParamCaption}\item[{unsigned char}]{b\mbox{[}3\mbox{]},  }\item[{int $\ast$}]{x,  }\item[{int $\ast$}]{y,  }\item[{int $\ast$}]{flags }\end{DoxyParamCaption})}

{\itshape b} {\itshape x} {\itshape y} {\itshape flags} .

\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000219}{Todo}}]remove the unused return argument. \end{DoxyRefDesc}
\mbox{\Hypertarget{encoding_8c_aeead1c7cae8d2d87aa74a32f0eeae808}\label{encoding_8c_aeead1c7cae8d2d87aa74a32f0eeae808}} 
\index{encoding.c@{encoding.c}!decode\_tajima\_ternary@{decode\_tajima\_ternary}}
\index{decode\_tajima\_ternary@{decode\_tajima\_ternary}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{decode\_tajima\_ternary()}{decode\_tajima\_ternary()}}
{\footnotesize\ttfamily void decode\+\_\+tajima\+\_\+ternary (\begin{DoxyParamCaption}\item[{unsigned char}]{b\mbox{[}3\mbox{]},  }\item[{int $\ast$}]{x,  }\item[{int $\ast$}]{y }\end{DoxyParamCaption})}

Decode the signed ternary of the tajima format from {\itshape b} to the position values {\itshape x} and {\itshape y}.

There is no return argument. \mbox{\Hypertarget{encoding_8c_a1fe39861516c14e3142add13ce9929b1}\label{encoding_8c_a1fe39861516c14e3142add13ce9929b1}} 
\index{encoding.c@{encoding.c}!decodeNewStitch@{decodeNewStitch}}
\index{decodeNewStitch@{decodeNewStitch}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{decodeNewStitch()}{decodeNewStitch()}}
{\footnotesize\ttfamily int decode\+New\+Stitch (\begin{DoxyParamCaption}\item[{unsigned char}]{value }\end{DoxyParamCaption})}



{\itshape value} 

\begin{DoxyReturn}{Returns}
int 
\end{DoxyReturn}
\mbox{\Hypertarget{encoding_8c_a49c180e69d4ac6d46e68b64adb74d7ae}\label{encoding_8c_a49c180e69d4ac6d46e68b64adb74d7ae}} 
\index{encoding.c@{encoding.c}!embColor\_fromHexStr@{embColor\_fromHexStr}}
\index{embColor\_fromHexStr@{embColor\_fromHexStr}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{embColor\_fromHexStr()}{embColor\_fromHexStr()}}
{\footnotesize\ttfamily \mbox{\hyperlink{embroidery_8h_acde9d757854564332fd795a084ec88b3}{Emb\+Color}} emb\+Color\+\_\+from\+Hex\+Str (\begin{DoxyParamCaption}\item[{char $\ast$}]{val }\end{DoxyParamCaption})}



Converts a 6 digit hex string (I.\+E. \char`\"{}00\+FF00\char`\"{}) into an Emb\+Color and returns it. 

{\itshape val} 6 byte code describing the color as a hex string, doesn\textquotesingle{}t require null termination. \begin{DoxyReturn}{Returns}
Emb\+Color the same color as our internal type. 
\end{DoxyReturn}
\mbox{\Hypertarget{encoding_8c_ac14e60a4d0a0fae16f22ccbbb2373e2a}\label{encoding_8c_ac14e60a4d0a0fae16f22ccbbb2373e2a}} 
\index{encoding.c@{encoding.c}!embInt\_read@{embInt\_read}}
\index{embInt\_read@{embInt\_read}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{embInt\_read()}{embInt\_read()}}
{\footnotesize\ttfamily void emb\+Int\+\_\+read (\begin{DoxyParamCaption}\item[{FILE $\ast$}]{f,  }\item[{char $\ast$}]{label,  }\item[{void $\ast$}]{b,  }\item[{int}]{mode }\end{DoxyParamCaption})}

{\itshape f} {\itshape label} {\itshape b} {\itshape mode} 

Read and write system for multiple byte types.

The caller passes the function to read/write from, the memory location as a void pointer and a mode identifier that describes the type. This way we can abstract out the endianness of the system running the library and don\textquotesingle{}t have to maintain many functions, just two. \mbox{\Hypertarget{encoding_8c_a6afc577513abd5034e24efdcbdd7f9f5}\label{encoding_8c_a6afc577513abd5034e24efdcbdd7f9f5}} 
\index{encoding.c@{encoding.c}!embInt\_write@{embInt\_write}}
\index{embInt\_write@{embInt\_write}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{embInt\_write()}{embInt\_write()}}
{\footnotesize\ttfamily void emb\+Int\+\_\+write (\begin{DoxyParamCaption}\item[{FILE $\ast$}]{f,  }\item[{char $\ast$}]{label,  }\item[{void $\ast$}]{b,  }\item[{int}]{mode }\end{DoxyParamCaption})}

{\itshape f} {\itshape label} {\itshape b} {\itshape mode} \mbox{\Hypertarget{encoding_8c_a185446b8993b1f6a16bca08cc0032cba}\label{encoding_8c_a185446b8993b1f6a16bca08cc0032cba}} 
\index{encoding.c@{encoding.c}!encode\_t01\_record@{encode\_t01\_record}}
\index{encode\_t01\_record@{encode\_t01\_record}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{encode\_t01\_record()}{encode\_t01\_record()}}
{\footnotesize\ttfamily void encode\+\_\+t01\+\_\+record (\begin{DoxyParamCaption}\item[{unsigned char}]{b\mbox{[}3\mbox{]},  }\item[{int}]{x,  }\item[{int}]{y,  }\item[{int}]{flags }\end{DoxyParamCaption})}

Encode into bytes {\itshape b} the values of the x-\/position {\itshape x}, y-\/position {\itshape y} and the {\itshape flags}. \mbox{\Hypertarget{encoding_8c_a6f2eb7f943597426ecce56ce45c92896}\label{encoding_8c_a6f2eb7f943597426ecce56ce45c92896}} 
\index{encoding.c@{encoding.c}!encode\_tajima\_ternary@{encode\_tajima\_ternary}}
\index{encode\_tajima\_ternary@{encode\_tajima\_ternary}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{encode\_tajima\_ternary()}{encode\_tajima\_ternary()}}
{\footnotesize\ttfamily int encode\+\_\+tajima\+\_\+ternary (\begin{DoxyParamCaption}\item[{unsigned char}]{b\mbox{[}3\mbox{]},  }\item[{int}]{x,  }\item[{int}]{y }\end{DoxyParamCaption})}

Encode the signed ternary of the tajima format into {\itshape b} the position values {\itshape x} and {\itshape y}.

If the values of {\itshape x} or {\itshape y} fall outside of the valid range of -\/121 and +121 then it returns 0 and 1. \mbox{\Hypertarget{encoding_8c_a896703c85b788f1c46053d826cdd3524}\label{encoding_8c_a896703c85b788f1c46053d826cdd3524}} 
\index{encoding.c@{encoding.c}!mitDecodeStitch@{mitDecodeStitch}}
\index{mitDecodeStitch@{mitDecodeStitch}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{mitDecodeStitch()}{mitDecodeStitch()}}
{\footnotesize\ttfamily int mit\+Decode\+Stitch (\begin{DoxyParamCaption}\item[{unsigned char}]{value }\end{DoxyParamCaption})}



{\itshape value} 

\begin{DoxyReturn}{Returns}
int 
\end{DoxyReturn}
\mbox{\Hypertarget{encoding_8c_a558c902db31be6221139e394313e4a0c}\label{encoding_8c_a558c902db31be6221139e394313e4a0c}} 
\index{encoding.c@{encoding.c}!mitEncodeStitch@{mitEncodeStitch}}
\index{mitEncodeStitch@{mitEncodeStitch}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{mitEncodeStitch()}{mitEncodeStitch()}}
{\footnotesize\ttfamily unsigned char mit\+Encode\+Stitch (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{embroidery_8h_a2082be9aabfb541dff1825c4ca6a05cd}{Emb\+Real}}}]{value }\end{DoxyParamCaption})}



{\itshape value} 

\begin{DoxyReturn}{Returns}
unsigned char 
\end{DoxyReturn}
\mbox{\Hypertarget{encoding_8c_a43cfefba2fb750ffa5eca5b7749b53f9}\label{encoding_8c_a43cfefba2fb750ffa5eca5b7749b53f9}} 
\index{encoding.c@{encoding.c}!pfaffDecode@{pfaffDecode}}
\index{pfaffDecode@{pfaffDecode}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{pfaffDecode()}{pfaffDecode()}}
{\footnotesize\ttfamily \mbox{\hyperlink{embroidery_8h_a2082be9aabfb541dff1825c4ca6a05cd}{Emb\+Real}} pfaff\+Decode (\begin{DoxyParamCaption}\item[{unsigned char}]{a1,  }\item[{unsigned char}]{a2,  }\item[{unsigned char}]{a3 }\end{DoxyParamCaption})}

Decode the bytes {\itshape a1}, {\itshape a2} and {\itshape a3} . Returns the Emb\+Real floating-\/point value. \mbox{\Hypertarget{encoding_8c_a2b001600fdee799e57a8ea00e9b73583}\label{encoding_8c_a2b001600fdee799e57a8ea00e9b73583}} 
\index{encoding.c@{encoding.c}!pfaffEncode@{pfaffEncode}}
\index{pfaffEncode@{pfaffEncode}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{pfaffEncode()}{pfaffEncode()}}
{\footnotesize\ttfamily void pfaff\+Encode (\begin{DoxyParamCaption}\item[{FILE $\ast$}]{file,  }\item[{int}]{dx,  }\item[{int}]{dy,  }\item[{int}]{flags }\end{DoxyParamCaption})}

{\itshape file} {\itshape dx} {\itshape dy} {\itshape flags} \mbox{\Hypertarget{encoding_8c_ad8b4161c499a38795d7a740300d9e5bd}\label{encoding_8c_ad8b4161c499a38795d7a740300d9e5bd}} 
\index{encoding.c@{encoding.c}!reverse\_byte\_order@{reverse\_byte\_order}}
\index{reverse\_byte\_order@{reverse\_byte\_order}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{reverse\_byte\_order()}{reverse\_byte\_order()}}
{\footnotesize\ttfamily void reverse\+\_\+byte\+\_\+order (\begin{DoxyParamCaption}\item[{void $\ast$}]{b,  }\item[{int}]{bytes }\end{DoxyParamCaption})}

Reverses the byte order of {\itshape bytes} number of bytes at memory location {\itshape b}. Only works for 2 or 4 byte arrays. \mbox{\Hypertarget{encoding_8c_a05863b88d4cb505762fa5c5ec4191224}\label{encoding_8c_a05863b88d4cb505762fa5c5ec4191224}} 
\index{encoding.c@{encoding.c}!write\_24bit@{write\_24bit}}
\index{write\_24bit@{write\_24bit}!encoding.c@{encoding.c}}
\doxyparagraph{\texorpdfstring{write\_24bit()}{write\_24bit()}}
{\footnotesize\ttfamily void write\+\_\+24bit (\begin{DoxyParamCaption}\item[{FILE $\ast$}]{file,  }\item[{int}]{x }\end{DoxyParamCaption})}



{\itshape file} {\itshape x} 

